﻿using System;
using Glue;
using Xunit;

namespace GlueTests.MapperTests
{
    public class When_passing_null_to_the_mapper
    {
        private readonly Mapping<DomainPerson, GuiPerson> mapping;

        public class DomainPerson { public String Name { get; set; } }
        public class GuiPerson { public String Name { get; set; } }

        public When_passing_null_to_the_mapper()
        {
            mapping = new Mapping<DomainPerson, GuiPerson>();
            mapping.Relate(domain => domain.Name, gui => gui.Name);
        }

        [Fact]
        public void Should_throw_meaningful_exception_when_toObject_is_null_TowardsRight()
        {
            Assert.Throws<GlueException>( ()=>
                mapping.Map(new DomainPerson {Name = "Tore"}, null)
            );
        }

        [Fact]
        public void Should_throw_meaningful_exception_when_fromObject_is_null_TowardsRight()
        {
            Assert.Throws<GlueException>( ()=>
                mapping.Map(null, new GuiPerson {Name = "Tore"})
            );
        }

        [Fact]
        public void Should_throw_meaningful_exception_when_toObject_is_null_TowardsLeft()
        {
            Assert.Throws<GlueException>(() =>
                mapping.Map(null, new DomainPerson { Name = "Tore" })
            );
        }

        [Fact]
        public void Should_throw_meaningful_exception_when_fromObject_is_null_TowardsLeft()
        {
            Assert.Throws<GlueException>(() =>
                mapping.Map(new GuiPerson {Name = "Tore"}, null)
            );
        }
    }
}
